package com.剑指offer;

public class _46孩子们的圆圈_礼物问题
{
    public static void main(String[] args)
    {
        System.out.println(LastRemaining_Solution(6, 1));
    }

    public static int LastRemaining_Solution(int n, int m)
    {
        if (n < 1 || m < 1)
        {
            return -1;
        }
        int array[] = new int[n];
        int i = -1;
        int step = 0;
        int count = n;
        while (count > 0)
        {
            i++;
            if (i >= n)
            {
                i = 0;
            }
            if (array[i] == -1)
            {
                continue;
            }
            step++;
            if (step == m)
            {
                step = 0;
                count--;
                array[i] = -1;

            }
        }
        return i;
    }
}
